﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
    public class LoaiKhachHangDAO
    {
        public class SqlConnectionData
        {
            public static SqlConnection Connection()
            {
                SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=QLKS;Integrated Security=True");
                return conn;
            }
        }

        public static DataTable GetAll()
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_LoaiKhachHangGetAll", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;

        }
        public static void InsertLoaiKhach(LoaiKhachHangDTO lkh)
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_InsertLoaiKhach", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@TenLoaiKhach", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@HeSoLoaiKhach", SqlDbType.Float);
            cmd.Parameters["@TenLoaiKhach"].Value = lkh.TenLoaiKhach;
            cmd.Parameters["@HeSoLoaiKhach"].Value = lkh.HeSoLoaiKhach;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public static void UpdatetLoaiKhach(LoaiKhachHangDTO lkh)
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_UpdateLoaiKhach", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaLoaiKhach", SqlDbType.Int);
            cmd.Parameters.Add("@TenLoaiKhach", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@HeSoLoaiKhach", SqlDbType.Float);
            cmd.Parameters["@MaLoaiKhach"].Value = lkh.MaLoaiKhach;
            cmd.Parameters["@TenLoaiKhach"].Value = lkh.TenLoaiKhach;
            cmd.Parameters["@HeSoLoaiKhach"].Value = lkh.HeSoLoaiKhach;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public static DataTable HeSoLoaiKhachTheoMaLoai(int MaLoaiKhach)
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_HeSoTheoMaLoaiKhach", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaLoaiKhach", SqlDbType.Int);
            cmd.Parameters["@MaLoaiKhach"].Value = MaLoaiKhach;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }

    }
}
